package com.kfm.servlet;

import com.kfm.model.KfmUser;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user")
public class UserServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String type = req.getParameter("type");
        switch (type) {
            case "edit" -> {
                String id = req.getParameter("id");
                KfmUser user = new KfmUser("张三", "12345678901", "123456", "1300@qq.com");
                req.setAttribute("username", user.getUsername());
                req.setAttribute("phone", user.getPhone());
                req.setAttribute("password", user.getPassword());
                req.setAttribute("email", user.getEmail());
                req.getRequestDispatcher("/WEB-INF/edit.jsp").forward(req, resp);
            }
            case "delete" -> delete(req, resp);
            case "insert" -> req.getRequestDispatcher("/WEB-INF/insert.jsp").forward(req, resp);
        }
    }

    private void delete(HttpServletRequest req, HttpServletResponse resp) {
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
